/*
 * Copyright 2013 Mounir IDRASSI  (mounir.idrassi@idrix.fr, for IDRIX)
 *
 * This file is part of SimCardManager.
 *
 * SimCardManager is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * SimCardManager is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with SimCardManager.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

// MainDlg.h : interface of the CMainDlg class
//
/////////////////////////////////////////////////////////////////////////////

#pragma once

#include "PcscManager.h"

class CMainDlg : public CDialogImpl<CMainDlg>
{
public:
   enum { IDD = IDD_MAINDLG };
   CPcscMgr m_pcsc;
   CComboBox m_list;
   CButton m_viewAdn, m_viewFdn, m_viewSms;
   bool m_bConnected;
   bool m_bPinVerified;
   CString m_szPIN;
   CSimPhoneBook m_Fdn;
   CSimPhoneBook m_Adn;
   CSimSMSList m_SmsList;

   BEGIN_MSG_MAP(CMainDlg)
      MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
      COMMAND_ID_HANDLER(ID_APP_ABOUT, OnAppAbout)
      MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnStaticColor)
      COMMAND_ID_HANDLER(IDOK, OnOK)
      COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
      COMMAND_HANDLER(IDC_CONNECT, BN_CLICKED, OnBnClickedConnect)
      NOTIFY_HANDLER(IDC_SYSLINK1, NM_CLICK, OnNMClickSyslink1)
      COMMAND_HANDLER(IDC_VIEW_ADN, BN_CLICKED, OnBnClickedViewAdn)
      COMMAND_HANDLER(IDC_VIEW_FDN, BN_CLICKED, OnBnClickedViewFdn)
      COMMAND_HANDLER(IDC_VIEW_SMS, BN_CLICKED, OnBnClickedViewSms)
   END_MSG_MAP()

   LRESULT OnStaticColor(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
   {
      HDC hdc = (HDC) wParam;
      HWND hwnd = (HWND) lParam;

      bHandled = FALSE;

      if (  (hwnd == GetDlgItem(IDC_LIST).m_hWnd)  
         || (hwnd == GetDlgItem(IDC_ICCID).m_hWnd)
         || (hwnd == GetDlgItem(IDC_PIN1).m_hWnd)
         || (hwnd == GetDlgItem(IDC_PIN2).m_hWnd)
         || (hwnd == GetDlgItem(IDC_IMSI).m_hWnd)
         || (hwnd == GetDlgItem(IDC_ADN).m_hWnd)
         || (hwnd == GetDlgItem(IDC_FDN).m_hWnd)
         || (hwnd == GetDlgItem(IDC_SMS).m_hWnd)
         )
      {
         bHandled = TRUE;
         return (LRESULT) ::GetSysColorBrush( COLOR_WINDOW );
      }

      return NULL;
   }

   // Handler prototypes (uncomment arguments if needed):
   //	LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
   //	LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
   //	LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)

   LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
   LRESULT OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
   LRESULT OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
   LRESULT OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
   LRESULT OnBnClickedConnect(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);

   LRESULT OnNMClickSyslink1(int /*idCtrl*/, LPNMHDR pNMHDR, BOOL& /*bHandled*/);

   LONG VerifyPIN(CSimReader *pReader, CSimStatus& status);
   LRESULT OnBnClickedViewAdn(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
   LRESULT OnBnClickedViewFdn(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
   LRESULT OnBnClickedViewSms(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
};
